<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" href="/mdui/css/mdui.min.css">
    <script defer src="/mdui/js/mdui.min.js"></script>
    <script src="/js/axios.min.js"></script>
    <script src="/js/qs.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/vue.js"></script>


</head>
<body class="mdui-theme-primary-indigo mdui-theme-accent-pink">


<div class="mdui-container-fluid" id="app">
    <h1 class="mdui-text-color-theme">发送邮件</h1>
    <div class="mdui-textfield">
        <input class="mdui-textfield-input" type="text" placeholder="邮件主题" v-model="subjiect"/>
    </div>
    <div class="mdui-textfield">
        <textarea class="mdui-textfield-input" placeholder="邮件内容" v-model="content"></textarea>
    </div>
    <div>
        选择收件人
    </div>
    <!--    栅格布局每行显示4个格子-->
    <div class="mdui-row-md-4">
        <div class="mdui-col" v-for="u in users">
            <label class="mdui-checkbox">
                <input type="checkbox" :value="u.id"/>
                <i class="mdui-checkbox-icon"></i>
                {{u.name}}({{u.email}})
            </label>
        </div>

    </div>
    <div style="text-align: center">
        <button @click="send" class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-green-800">
            发送
        </button>

        <a href="javascript:history.back()"
           class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-green-800">返回</a>
    </div>
</div>
<script>
    let vm = new Vue({
        el: "#app",
        data: {
            users: [],
            subjiect: '',
            content: ''
        },
        created() {
            this.findUsers()
        },
        methods: {
            send: function () {
                if (this.subjiect == "" || this.content == "") {
                    mdui.alert("请输入内容")
                    return;
                }
                s = this.subjiect;
                c = this.content
                let ids = [];
                //选择的checked
                let arr = document.querySelectorAll("input:checked");
                for (let e of arr) {//for ....of,e就是当前的迭代的变量
                    ids.push(e.value);
                }
                axios.post("/mail/send?ids=" + ids.toString(),
                    Qs.stringify(
                        {
                            subjiect: this.subjiect,
                            content: this.content
                        }
                    ))
                    .then(function (res) {
                        if (res.data.success) {
                            mdui.alert("发送成功")
                        }
                    })
                console.log(this.subjiect)
            },
            findUsers() {
                let _this = this
                axios.get("/user/selectWithEmail")
                    .then(function (res) {
                        _this.users = res.data;
                    })
            }
        },

    })

</script>


</body>
</html>